package com.yequan.exe.core.task;

import com.yequan.exe.core.ExeExecutorExtListener;
import com.yequan.exe.core.handler.ExeHandler;
import com.yequan.pojo.CalcData;

/**
 * @author yq
 * @date 2020/09/27
 */
public class ExeExecutorTask implements Runnable {


    private ExeHandler exeHandler;

    private CalcData calcData;

    public ExeExecutorTask(ExeHandler exeHandler, CalcData calcData) {
        this.exeHandler = exeHandler;
        this.calcData = calcData;
    }

    @Override
    public void run() {
        exeHandler.combineCommand(calcData);
        exeHandler.beforeExecute(calcData);
        int result = exeHandler.execute(calcData);
        exeHandler.afterExecute(calcData, result);
        ExeExecutorExtListener exeExecutorExtListener = exeHandler.getExeExecutorListener();
        if (null != exeExecutorExtListener) {
            exeExecutorExtListener.afterExecuteExt(calcData, result);
        }
    }
}
